package com.ftg.learn.day05;

import java.util.Scanner;

/**
 * 学习一下dowhile
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/7/12 下午3:27
 */
public class DoWhile01 {

    /**
     * 用来完成青蛙跳井
     *
     * @param well 井深
     * @param jump 一次跳几米
     * @param down 如果没有出去下滑几米
     * @return 次数
     */
    public static int frogJumpWell(int well, int jump, int down) {

        if (jump > well) {
            return 1;
        }

        if (jump < down) {
            return -1;
        }

        int num = 0;
        int frog = 0;
        do {
            if (num != 0) {
                frog -= down;
            }
            frog += jump;
            num++;
        } while (frog < well);

        return num;
    }

    public static void main(String[] args) {

        System.out.println("---------------------------------------");
        System.out.println("-------                           -----");
        System.out.println("--------------*----*-------------------");
        System.out.println("-------                           -----");
        System.out.println("---------------------------------------");
        Scanner s  = new Scanner(System.in);
        System.out.println("尊敬的老板您好，请您输入青蛙所在的井的深度");
        int well = s.nextInt();
        System.out.println("尊敬的老板您好，请您输入青蛙一次跳几米");
        int jump = s.nextInt();
        System.out.println("尊敬的老板您好，请您输入青蛙下滑几米");
        int down = s.nextInt();
        int num = frogJumpWell(well,jump,down);
        System.out.println("尊敬的老板您好，你家的哈摸"+num+"就可以跳出来了");

        //代码重用性 : --> 北 (一个媳妇)

//        int well = 15;
//        int jump = 8;
//        int down = 2;
//        int frog = 0;
//        int num = 0;
//
//        //容错
//
//        if(jump < down){
//            System.out.println("你出不去");
//        }else if(jump > well){
//            System.out.println("1次");
//        }else{
//
//            do {
//                if (num != 0) {
//                    frog -= down;
//                }
//                frog += jump;
//                num++;
//            } while (frog < well);
//
//            System.out.println(num);
//        }
    }

}
